package com.elastic.job.config;

import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnBean
public class JobRegistryCenterConfig {

    @Bean(initMethod = "init")
    public ZookeeperRegistryCenter regCenter(
            @Value("${regCenter.serverList}") final String serverList,
            @Value("${regCenter.namespace}") final String namespace) {
        return new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, namespace));
    }

//    @ConditionalOnBean         //	当给定的在bean存在时,则实例化当前Bean
//    @ConditionalOnMissingBean  //	当给定的在bean不存在时,则实例化当前Bean
//    @ConditionalOnClass        //	当给定的类名在类路径上存在，则实例化当前Bean
//    @ConditionalOnMissingClass //	当给定的类名在类路径上不存在，则实例化当前Bean
}